{{!

  Copyright (c) Meta Platforms, Inc. and affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}{{#struct:fields}}{{#field:type}}
{{#field:boxed_ref?}}
 private:
{{/field:boxed_ref?}}
{{^field:boxed_ref?}}{{^struct:legacy_api?}}
 private:
{{/struct:legacy_api?}}{{/field:boxed_ref?}}
  {{#type:resolves_to_base_or_enum?}}

  {{^type:string_or_binary?}}
  {{> common/field_docblock}}
  template <typename... A, std::enable_if_t<!sizeof...(A), int> = 0>
  {{!deprecated}}{{field:cpp_storage_type}}& set_{{field:cpp_name}}({{field:cpp_type}} t = {{field:cpp_type}}()) {
    using T0 = {{field:cpp_storage_type}};
    using T = folly::type_t<T0, A...>;
    __fbthrift_clear();
    fbthrift_type_ = folly::to_underlying(Type::{{field:cpp_name}});
{{#field:cpp_ref?}}
    ::new (std::addressof(value_.{{field:cpp_name}})) T({{^field:boxed_ref?}}new {{/field:boxed_ref?}}typename T::element_type(t));
{{/field:cpp_ref?}}
{{^field:cpp_ref?}}
    ::new (std::addressof(value_.{{field:cpp_name}})) T(t);
{{/field:cpp_ref?}}
    return value_.{{field:cpp_name}};
  }
  {{/type:string_or_binary?}}
  {{#type:string_or_binary?}}
  {{> common/field_docblock}}
  template <typename... A, std::enable_if_t<!sizeof...(A), int> = 0>
  {{!deprecated}}{{field:cpp_storage_type}}& set_{{field:cpp_name}}({{field:cpp_type}} const &t) {
    using T0 = {{field:cpp_storage_type}};
    using T = folly::type_t<T0, A...>;
    __fbthrift_clear();
    fbthrift_type_ = folly::to_underlying(Type::{{field:cpp_name}});
{{#field:cpp_ref?}}
    ::new (std::addressof(value_.{{field:cpp_name}})) T({{^field:boxed_ref?}}new {{/field:boxed_ref?}}typename T::element_type(t));
{{/field:cpp_ref?}}
{{^field:cpp_ref?}}
    ::new (std::addressof(value_.{{field:cpp_name}})) T(t);
{{/field:cpp_ref?}}
    return value_.{{field:cpp_name}};
  }

  {{> common/field_docblock}}
  template <typename... A, std::enable_if_t<!sizeof...(A), int> = 0>
  {{!deprecated}}{{field:cpp_storage_type}}& set_{{field:cpp_name}}({{field:cpp_type}}&& t) {
    using T0 = {{field:cpp_storage_type}};
    using T = folly::type_t<T0, A...>;
    __fbthrift_clear();
    fbthrift_type_ = folly::to_underlying(Type::{{field:cpp_name}});
{{#field:cpp_ref?}}
    ::new (std::addressof(value_.{{field:cpp_name}})) T({{^field:boxed_ref?}}new {{/field:boxed_ref?}}typename T::element_type(std::move(t)));
{{/field:cpp_ref?}}
{{^field:cpp_ref?}}
    ::new (std::addressof(value_.{{field:cpp_name}})) T(std::move(t));
{{/field:cpp_ref?}}
    return value_.{{field:cpp_name}};
  }

  {{!deprecated}}
  {{> common/field_docblock}}
  template<typename... T, typename = ::apache::thrift::safe_overload_t<{{field:cpp_type}}, T...>> {{field:cpp_storage_type}}& set_{{field:cpp_name}}(T&&... t) {
    __fbthrift_clear();
    fbthrift_type_ = folly::to_underlying(Type::{{field:cpp_name}});
{{#field:cpp_ref?}}
    ::new (std::addressof(value_.{{field:cpp_name}})) {{field:cpp_storage_type}}({{^field:boxed_ref?}}new {{/field:boxed_ref?}}{{field:cpp_storage_type}}::element_type(std::forward<T>(t)...));
{{/field:cpp_ref?}}
{{^field:cpp_ref?}}
    ::new (std::addressof(value_.{{field:cpp_name}})) {{field:cpp_type}}(std::forward<T>(t)...);
{{/field:cpp_ref?}}
    return value_.{{field:cpp_name}};
  }
  {{/type:string_or_binary?}}

{{#field:cpp_ref?}}
  {{> common/field_docblock}}
  {{!deprecated}}{{field:cpp_storage_type}}& set_{{field:cpp_name}}({{field:cpp_storage_type}} t) {
    __fbthrift_clear();
    fbthrift_type_ = folly::to_underlying(Type::{{field:cpp_name}});
    ::new (std::addressof(value_.{{field:cpp_name}})) {{field:cpp_storage_type}}(std::move(t));
    return value_.{{field:cpp_name}};
  }
{{/field:cpp_ref?}}
  {{/type:resolves_to_base_or_enum?}}
  {{#type:resolves_to_container_or_struct?}}
  {{^field:cpp_ref?}}

  {{^field:cpp_noncopyable?}}
  {{> common/field_docblock}}
  template <typename... A, std::enable_if_t<!sizeof...(A), int> = 0>
  {{!deprecated}}
  {{field:cpp_storage_type}}& set_{{field:cpp_name}}({{field:cpp_type}} const &t) {
    using T0 = {{field:cpp_storage_type}};
    using T = folly::type_t<T0, A...>;
    __fbthrift_clear();
    fbthrift_type_ = folly::to_underlying(Type::{{field:cpp_name}});
    ::new (std::addressof(value_.{{field:cpp_name}})) T(t);
    return value_.{{field:cpp_name}};
  }
  {{/field:cpp_noncopyable?}}

  {{> common/field_docblock}}
  template <typename... A, std::enable_if_t<!sizeof...(A), int> = 0>
  {{!deprecated}}{{field:cpp_storage_type}}& set_{{field:cpp_name}}({{field:cpp_type}}&& t) {
    using T0 = {{field:cpp_storage_type}};
    using T = folly::type_t<T0, A...>;
    __fbthrift_clear();
    fbthrift_type_ = folly::to_underlying(Type::{{field:cpp_name}});
    ::new (std::addressof(value_.{{field:cpp_name}})) T(std::move(t));
    return value_.{{field:cpp_name}};
  }

  {{!deprecated}}
  {{> common/field_docblock}}
  template<typename... T, typename = ::apache::thrift::safe_overload_t<{{field:cpp_type}}, T...>> {{field:cpp_storage_type}}& set_{{field:cpp_name}}(T&&... t) {
    __fbthrift_clear();
    fbthrift_type_ = folly::to_underlying(Type::{{field:cpp_name}});
    ::new (std::addressof(value_.{{field:cpp_name}})) {{field:cpp_type}}(std::forward<T>(t)...);
    return value_.{{field:cpp_name}};
  }
  {{/field:cpp_ref?}}
  {{#field:cpp_ref?}}
  {{!deprecated}}{{field:cpp_storage_type}}& set_{{field:cpp_name}}({{field:cpp_storage_type}} t);
  {{!deprecated}}{{field:cpp_storage_type}}& set_{{field:cpp_name}}({{field:cpp_type}} const &t);
  {{!deprecated}}{{field:cpp_storage_type}}& set_{{field:cpp_name}}({{field:cpp_type}}&& t);
  {{!deprecated}}
  {{> common/field_docblock}}
  template<typename... T, typename = ::apache::thrift::safe_overload_t<{{field:cpp_type}}, T...>> {{field:cpp_storage_type}}& set_{{field:cpp_name}}(T&&... t) {
    // defer resolution of ref_ in case ref_::element_type would here be incomplete
    using ref_ = folly::conditional_t<(sizeof...(T) < size_t(-1)), {{field:cpp_storage_type}}, void>;
    __fbthrift_clear();
    fbthrift_type_ = folly::to_underlying(Type::{{field:cpp_name}});
    ::new (std::addressof(value_.{{field:cpp_name}})) ref_({{^field:boxed_ref?}}new {{/field:boxed_ref?}}typename ref_::element_type(std::forward<T>(t)...));
    return value_.{{field:cpp_name}};
  }
  {{/field:cpp_ref?}}
  {{/type:resolves_to_container_or_struct?}}
{{#field:boxed_ref?}}
 public:
{{/field:boxed_ref?}}
{{^field:boxed_ref?}}{{^struct:legacy_api?}}
 public:
{{/struct:legacy_api?}}{{/field:boxed_ref?}}
{{/field:type}}{{/struct:fields}}
